<template>
  <div>
    <!-- Form -->
    
      <el-form :model="form">
        <el-form-item label="账号" :label-width="formLabelWidth">
          <el-input v-model="user.username" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="user.password" autocomplete="off" :show-password="true"></el-input>
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="()=>{dialogFormVisible = false;$emit('close')}">取 消</el-button>
        
        <el-button type="primary" @click="submit()"
          >登陆</el-button
        >
      </div>
  </div>
</template>

<script>
import { login } from '../api/index'
export default {
  name: "Login",
  data() {
    return {
      // 已登陆
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      user: {
          username:'',
          password: ''
      },
      formLabelWidth: "120px",
    };
  },
  methods: {
      submit() {
          login(this.user.username, this.user.password).then(res => {
            let type = res.code === 1? 'success': 'error';
            this.$message({message: res.msg, type: type})
            if (res.code === 1) {
              window.localStorage.setItem('userInfo', JSON.stringify(this.user))
              this.$emit('success')
            }

          })
          // this.$message({message: '登陆成功', type: 'success'})
          
      }
  },
  mounted() {
    //   this.dialogFormVisible = this.open;
    
  },

  props: {
    open: Boolean,
  },
};
</script>

<style scoped>
</style>
